package com.neusoft.ysu.npms.controller;


import com.neusoft.ysu.npms.pojo.Category;
import com.neusoft.ysu.npms.pojo.Measure;
import com.neusoft.ysu.npms.pojo.Result;
import com.neusoft.ysu.npms.service.CategoryService;
import com.neusoft.ysu.npms.service.IMeasureService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 作者：刘金秋
 * @since 2024-06-18
 */
@RestController
@RequestMapping("/measure")
public class MeasureController {
    @Autowired
    private IMeasureService measureService;


    @RequestMapping("/add")
    public Result add(@RequestBody Measure measure){
        measureService.save(measure);
        return Result.success();
    }

    @RequestMapping("/delete")
    public Result delete(@RequestBody Map<String, Object> body){
        System.out.println(body.get("measureid"));
        return measureService.deleteByMeasureId((int)body.get("measureid"));
        //return Result.success();
    }

    @RequestMapping("update")
//    public Result update(@RequestParam("measureid") Integer id){
    public Result update(@RequestBody Measure measure){
//        System.out.println(body.get("measureid"));
//        System.out.println(body.get("measurename"));
        measureService.updateByMeasureId(measure);
        return Result.success();
    }

    @RequestMapping("getAll")
    public Result getAll(){
        return measureService.selectAll();
    }

    @RequestMapping("findone")
    public Result findone(@RequestBody Measure measure){
        System.out.println(measure);
        return measureService.findById(measure);
    }
}
